#!/usr/bin/env python
# coding: utf8


from flask import Flask, request, render_template
import os


app = Flask(__name__)


@app.route('/')
def index():
	port = request.args.get("port")
	vm_id = request.args.get("vm_id")
	timeout = request.args.get("timeout", 10)
	host = request.host.split(":")[0]
	cmd = "python websockify/run {port} --unix-target /var/run/qemu-server/{vm_id}.vnc --timeout={timeout} -D".format(port=port, vm_id=vm_id, timeout=timeout)
	os.system(cmd)
	return render_template("vnc_lite.html", port=port, host=host)


if __name__ == '__main__':
	app.run(host="0.0.0.0", port="8989")
